package com.shop2cn.iapi.wxcomponent.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.wxcomponent.parameter.CheckAuditVersionBean;
import com.shop2cn.iapi.wxcomponent.service.CheckAuditVersionCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.WxComponentService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.Auditrecord;
import com.ymttest.database.sqlwapper.godmch.DefGodMchWapper;
import com.ymttest.utils.YMTDateUtil;
/**
*检查版本是否在审核中Test
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_CheckAuditVersion{
	private static CheckAuditVersionBean checkauditversionBean;
	private static CheckAuditVersionCall checkauditversionCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("检查版本是否在审核中Test");
	}

	@Before
	public void caseUp() {
		checkauditversionBean=new CheckAuditVersionBean();
		checkauditversionCall=new CheckAuditVersionCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(checkauditversionCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CheckAuditVersion_001() {
		Logger.start(true,"已经提审小程序查询成功");
		try {
			Integer mchid = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
            WxComponentService.deleteMchinfo(mchid);
            String appid = WxComponentService.ConfirmAuthorization(mchid);
            WxComponentService.Remark("啊哈哈", mchid);
            WxComponentService.ApplyCharge(mchid);
			WxComponentService.ChargeNotify(mchid);
			WxComponentService.ConfirmAuditMchApp(mchid);
			
			checkauditversionBean.setMchId(mchid);
			checkauditversionBean.setVersion("autotest1");
			checkauditversionCall.setData(checkauditversionBean);
			checkauditversionCall.callService();			
			Logger.verifyEquals("200", checkauditversionCall.getString("code"), "验证code");
			Logger.verifyEquals(true, checkauditversionCall.getJsonObject().get("data").getAsBoolean(), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CheckAuditVersion_0011() {
		Logger.start(true,"提审通过小程序查询成功");
		try {
			
			checkauditversionBean.setMchId(500449318);
			checkauditversionBean.setVersion("autotest1");
			checkauditversionCall.setData(checkauditversionBean);
			checkauditversionCall.callService();			
			Logger.verifyEquals("200", checkauditversionCall.getString("code"), "验证code");
			Logger.verifyEquals(false, checkauditversionCall.getJsonObject().get("data").getAsBoolean(), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CheckAuditVersion_0012() {
		Logger.start(true,"审核失败小程序查询成功");
		try {
			
			checkauditversionBean.setMchId(500449317);
			checkauditversionBean.setVersion("autotest1");
			checkauditversionCall.setData(checkauditversionBean);
			checkauditversionCall.callService();			
			Logger.verifyEquals("200", checkauditversionCall.getString("code"), "验证code");
			Logger.verifyEquals(false, checkauditversionCall.getJsonObject().get("data").getAsBoolean(), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CheckAuditVersion_0013() {
		Logger.start(true,"审核延后小程序查询成功");
		try {
			
			checkauditversionBean.setMchId(500449316);
			checkauditversionBean.setVersion("autotest1");
			checkauditversionCall.setData(checkauditversionBean);
			checkauditversionCall.callService();			
			Logger.verifyEquals("200", checkauditversionCall.getString("code"), "验证code");
			Logger.verifyEquals(false, checkauditversionCall.getJsonObject().get("data").getAsBoolean(), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CheckAuditVersion_0014() {
		Logger.start(true,"审核撤回小程序查询成功");
		try {
			
			checkauditversionBean.setMchId(500449309);
			checkauditversionBean.setVersion("autotest1");
			checkauditversionCall.setData(checkauditversionBean);
			checkauditversionCall.callService();			
			Logger.verifyEquals("200", checkauditversionCall.getString("code"), "验证code");
			Logger.verifyEquals(false, checkauditversionCall.getJsonObject().get("data").getAsBoolean(), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CheckAuditVersion_002() {
		Logger.start(true,"还未提审小程序查询成功");
		try {
			Integer mchid = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
            WxComponentService.deleteMchinfo(mchid);
            String appid = WxComponentService.ConfirmAuthorization(mchid);
            WxComponentService.Remark("啊哈哈", mchid);
            WxComponentService.ApplyCharge(mchid);
			WxComponentService.ChargeNotify(mchid);
			
			checkauditversionBean.setMchId(mchid);
			checkauditversionBean.setVersion("autotest1");
			checkauditversionCall.setData(checkauditversionBean);
			checkauditversionCall.callService();			
			Logger.verifyEquals("400", checkauditversionCall.getString("code"), "验证code");
			Logger.verifyIsContains("不存在此版本号", checkauditversionCall.getString("message"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CheckAuditVersion_003() {
		Logger.start(true,"新创建的小程序查询成功");
		try {
			Integer mchid = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
            WxComponentService.deleteMchinfo(mchid);
            String appid = WxComponentService.ConfirmAuthorization(mchid);

            
            checkauditversionBean.setMchId(mchid);
			checkauditversionBean.setVersion("autotest1");
			checkauditversionCall.setData(checkauditversionBean);
			checkauditversionCall.callService();			
			Logger.verifyEquals("400", checkauditversionCall.getString("code"), "验证code");
			Logger.verifyIsContains("不存在此版本号", checkauditversionCall.getString("message"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CheckAuditVersion_004() {
		Logger.start(true,"mchid为空，查询失败");
		try {
			Integer mchid = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
            WxComponentService.deleteMchinfo(mchid);
            String appid = WxComponentService.ConfirmAuthorization(mchid);
            WxComponentService.Remark("啊哈哈", mchid);
            WxComponentService.ApplyCharge(mchid);
			WxComponentService.ChargeNotify(mchid);
			WxComponentService.ConfirmAuditMchApp(mchid);
			WxComponentService.AuthorizationCallBack(appid, "authorized");
			
//			checkauditversionBean.setMchId(mchid);
			checkauditversionBean.setVersion("autotest1");
			checkauditversionCall.setData(checkauditversionBean);
			checkauditversionCall.callService();			
			Logger.verifyEquals("400", checkauditversionCall.getString("code"), "验证code");
			Logger.verifyIsContains("商户号不能为空", checkauditversionCall.getString("message"), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CheckAuditVersion_005() {
		Logger.start(true,"版本号为空，查询失败");
		try {
			Integer mchid = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
            WxComponentService.deleteMchinfo(mchid);
            String appid = WxComponentService.ConfirmAuthorization(mchid);
            WxComponentService.Remark("啊哈哈", mchid);
            WxComponentService.ApplyCharge(mchid);
			WxComponentService.ChargeNotify(mchid);
			WxComponentService.ConfirmAuditMchApp(mchid);
			WxComponentService.AuthorizationCallBack(appid, "authorized");
			
			checkauditversionBean.setMchId(mchid);
//			checkauditversionBean.setVersion("autotest1");
			checkauditversionCall.setData(checkauditversionBean);
			checkauditversionCall.callService();			
			Logger.verifyEquals("400", checkauditversionCall.getString("code"), "验证code");
			Logger.verifyIsContains("版本号version不能为空", checkauditversionCall.getString("message"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CheckAuditVersion_006() {
		Logger.start(true,"版本号错误，查询失败");
		try {
			Integer mchid = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
            WxComponentService.deleteMchinfo(mchid);
            String appid = WxComponentService.ConfirmAuthorization(mchid);
            WxComponentService.Remark("啊哈哈", mchid);
            WxComponentService.ApplyCharge(mchid);
			WxComponentService.ChargeNotify(mchid);
			WxComponentService.ConfirmAuditMchApp(mchid);
			WxComponentService.AuthorizationCallBack(appid, "authorized");
			
			checkauditversionBean.setMchId(mchid);
			checkauditversionBean.setVersion("autot1123est1");
			checkauditversionCall.setData(checkauditversionBean);
			checkauditversionCall.callService();			
			Logger.verifyEquals("400", checkauditversionCall.getString("code"), "验证code");
			Logger.verifyIsContains("不存在此版本号", checkauditversionCall.getString("message"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CheckAuditVersion_007() {
		Logger.start(true,"解绑后，判断审核状态");
		try {
			DefGodMchWapper defGodMchWapper = new DefGodMchWapper();
			//授权-付费提审
			Integer mchid = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
			WxComponentService.deleteMchinfo(mchid);
			WxComponentService.ApplyCharge(mchid);
			WxComponentService.ChargeNotify(mchid);
			String appid = WxComponentService.ConfirmAuthorization(mchid);
			WxComponentService.AuthorizationCallBack(appid, "authorized");
			WxComponentService.ConfirmAuditMchApp(mchid);
			Auditrecord auditrecord = defGodMchWapper.selectAuditrecordByExample(mchid).get(0);
			//取消授权--再次授权提审
			WxComponentService.CancelAuthorization(mchid);
			
			checkauditversionBean.setMchId(mchid);
			checkauditversionBean.setVersion("autotest1");
			checkauditversionCall.setData(checkauditversionBean);
			checkauditversionCall.callService();			
			Logger.verifyEquals("200", checkauditversionCall.getString("code"), "验证code");
			Logger.verifyEquals(true, checkauditversionCall.getJsonObject().get("data").getAsBoolean(), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
}